package com.bangdream.michelia.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @date on 2018/8/19 23:31
 * @email 909732184@qq.com
 * 提取括号中的内容
 */
public class ExtractMessageUtils {

    /**
     * 使用正则表达式提取中括号中的内容
     * @param msg
     * @return
     */
    public static List<String> extractMessageByRegular(String msg){
        List<String> list=new ArrayList<String>();
        //Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
        Pattern p = Pattern.compile("(\\([^\\)]+\\))");
        Matcher m = p.matcher(msg);
        while(m.find()){
            list.add(m.group().substring(1, m.group().length()-1));
        }
        return list;
    }

}
